package com.example.lenovo.weiyi;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import com.com.ruanmeng.demon.CommonM;
import com.com.ruanmeng.utils.CommonUtil;
import com.com.ruanmeng.utils.Params;
import com.com.ruanmeng.utils.PreferencesUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.Request;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import nohttp.CallServer;
import nohttp.CustomHttpListener;
import share.Const;
import share.HttpIP;

/**
 * Created by Administrator on 2017/5/5.
 */

public class YiJianFanKuiActivity extends BaseActivity {
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.et_fankui_content)
    EditText etFankuiContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yijian_fankui);
        ButterKnife.bind(this);
        ChangLayTitle("意见反馈");
    }

    @OnClick(R.id.btn_submit)
    public void onClick() {
        if (CommonUtil.getEditText(etFankuiContent).isEmpty()) {
            CommonUtil.showToask(this, "请输入您的反馈意见");
            return;
        }
        getData();
    }
    private void getData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.FanKui, Const.POST);
        mRequest.addHeader("token", PreferencesUtils.getString(YiJianFanKuiActivity.this, "uid"));
        mRequest.add("content", etFankuiContent.getText().toString());
        CallServer.getRequestInstance().add(YiJianFanKuiActivity.this, 0, mRequest,
                new CustomHttpListener(YiJianFanKuiActivity.this, true, CommonM.class) {

                    @Override
                    public void doWork(Object data, boolean isOne) {
                        CommonM model = ((CommonM) data);
                        finish();
                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                        CommonUtil.showToask(YiJianFanKuiActivity.this, obj.getString("msg"));
                    }
                }, true, true);
    }
}
